package com.gonsin.license;

import org.springframework.context.annotation.AdviceMode;
import org.springframework.context.annotation.AdviceModeImportSelector;
import org.springframework.context.annotation.AnnotationConfigUtils;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.type.AnnotationMetadata;

import java.util.Map;
import java.util.Set;

//@Configuration
//@ComponentScan
//@EnableConfigurationProperties
//@ComponentScan("com.gonsin.license")
public class GLicenseAutoSelector implements ImportSelector {

    /**
     * 该设备的系统类型
     */
    public static String DEVICE;

    @Override
    public String[] selectImports(AnnotationMetadata importingClassMetadata) {
//        Set<String> types = importingClassMetadata.getMetaAnnotationTypes(EnableGLicense.class.getName());
//        importingClassMetadata.getAnnotationTypes().forEach(System.out::println);
        Map<String, Object> params = importingClassMetadata.getAnnotationAttributes("com.gonsin.license.EnableGLicense");
        DEVICE = (String) params.get("device");
//        AnnotationAttributes attributes = AnnotationMetadata .attributesFor(importingClassMetadata, annType);
//        DEVICE = importingClassMetadata.getAnnotationAttributes("device");

        // 返回需要注入的类
        return new String[]{"com.gonsin.license.LicenseAutoConfiguration"};
    }
}
